<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr XMLNS:MSHelp = "http://msdn.microsoft.com/mshelp" xmlns:ddue = 
"http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink = 
"http://www.w3.org/1999/xlink" xmlns:tool = "http://www.microsoft.com/tooltip"
XMLNS:[default] http://ddue.schemas.microsoft.com/authoring/2003/5 =
"http://ddue.schemas.microsoft.com/authoring/2003/5"><HEAD>
  <TITLE>Windows Azure Service Bus Silverlight Chat Sample</TITLE>
  <META content="text/html; CHARSET=utf-8" http-equiv=Content-Type></META>
  <META name=save content=history></META>
  <LINK rel=stylesheet type=text/css
  href="../CommonFiles/Classic.css"></LINK>

  <META name=GENERATOR content="MSHTML 8.00.6001.18783">
    <style type="text/css">
      .style2 {
      font-family: monospace;
      font-size: small;
      color: #000000;
      }
      </style>
  </HEAD>
<BODY>
  <DIV id=header>
    <TABLE id=topTable width="100%">
      <TBODY>
        <TR id=headerTableRow1>
          <TD align=left>
            <SPAN id=runningHeaderText></SPAN>
          </TD>
        </TR>
        <TR id=headerTableRow2>
          <TD align=left>
            <SPAN id=nsrTitle>Windows Azure Service Bus Silverlight Chat Sample</SPAN>
          </TD>
        </TR>
        <TR id=headerTableRow3>
          <TD></TD>
        </TR>
      </TBODY>
    </TABLE>
  </DIV>
  <DIV id=mainSection>
    <DIV id=mainBody>
          <p>
            This sample demonstrates how to use various Windows Azure Service Bus Messaging Features from Silverlight through the REST Service Bus endpoint. The sample comes in two pieces. The <b>Microsoft.Samples.ServiceBus.Messaging</b> library includes a complete REST API for accessing Service Bus Messaging features from Silverlight; the <b>SilverlightChat</b> application is built using that library and shows how to build a Silverlight application which interacts with Service Bus messaging features and follows the MVVM pattern.
            See the Service Bus documentation for more information about the Service Bus before exploring the samples.
          </p>
          <p>
            This sample demonstrates:
          </p>
          <ol>
            <li>Retrieving an authorization token from the Access Control Service, determining its expiry time and renewing the token when necessary;</li>
            <li>Retrieving a list of topics within a service namespace and determining if a topic contains a named subscription;</li>
            <li>Adding topics to the service namespace and detecting conflicts with existing topics;</li>
            <li>Adding a subscription to a topic and receiving messages from that subscription;</li>
            <li>Receiving messages with PeekLock semantics including Completing messages when they are processed successfully and abandoning them otherwise;</li>
            <li>Sending messages to a topic and using Message Properties from the REST endpoint;</li>
            <li>Deleting topics and subscriptions</li>
          </ol>
          <p>
          In this sample, many participants can chat in multiple chat rooms by using the Service Bus. When the application starts, each user enters a unique username and clicks login.
          Then, a list of available 'Chat Rooms' (Topics) is downloaded. Users can subscribe to various rooms to receive updates from them even when they are not present in that room,
          they may send and receive messages in any room they are subscribed to.
          </p>
        <H2 class=heading>Prerequisites</H2>
      <DIV class=section>
        <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
          <P xmlns="">
            If you haven't already done so, please read the release notes
            document that explains how to sign up for a Windows Azure
            account and how to configure your environment.
          </P>
        </content>
      </DIV>
        <H2 class=heading>Before You Run the Sample</H2>
      <DIV class=section>
        <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
          <p>
            To compile and run the Silverlight Sample, you first need to have the <a href="http://go.microsoft.com/fwlink/?LinkID=177428">Silverlight 4 Tools for Visual Studio 2010</a> installed on your computer.
          </p>
          <p>
            To run the Windows Phone sample you first need to install the <a href="http://create.msdn.com/en-us/resources/downloads">Windows Phone Developer Tools</a>.
          </p>
          <p>
          In Silverlight, cross domain networking is restricted; any services you wish to call from a Silverlight application (including the Windows Azure Service Bus) are responsible for publishing a Client Access Policy file - you can learn more about <a href="http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx">Network Security Access Restrictions in Silverlight</a> on MSDN. This sample access network resources in two realms: firstly, an HTTP POST request is made to the Access Control Service; next HTTP POST, PUT and DELETE requests are made to the Service Bus. The Access Control Service publishes a default client access policy document which permits cross domain execution from all callers at the root of each namespace. The Service Bus, however, does not publish any policy by default; it is therefore necessary to upload a Client Access Policy document to the root of your service namespace - this can be done with the ClientAccessPolicyPublisher utility included with the samples. <b>You must ensure you have a Client Access Policy in place before running the sample or you will encounter Security Exceptions</b>.
          </p>
          <p>
            You must also update the class <b>ApplicationContext</b> to contain your Service Namespace name, Issuer Name and Issuer Secret before the sample can run. Open the file and update the code near the comment <i>// TODO: Enter your Service Namespace information here</i>
          </p>
          </content>
      </DIV>
    <H2 class=heading>Sample Flow</H2>
    <DIV class=section>
      <content
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
          <p>
            There is some flexibility in how the sample can procede, but the following flow is recommended
            <ol>
              <li>Before starting, be sure to open the source file <b>ApplicationContext.cs</b> and enter your namespace information (Service Namespace, Issuer Name, Issuer Secret) where indicated.</li>
              <li>Open the sample application in your favorite browser</li>
              <li>Type a unique name into the 'User name' box and login.</li>
              <li>The first time you login, there will be no 'Topics' listed on the left of the window. Click the green 'Add' button to create a new topic</li>
              <li>In the dialog, enter a name for the topic, confirm the 'Subscribe me to this topic' checkbox is checked and click ok</li>
              <li>The UI displays the newly created topic with a yellow star next to it - this star indicates that you are subscribed to the room.</li>
              <li>On the right, a large text area will contain messages in the chat room. There is a text box at the bottom of the window to enter new messages into.</li>
              <li>Type a message and hit 'Enter' - the message is sent to the service bus, received immediately and displayed in the large text area.</li>
              <li>Open a second browser window and navigate to the sample application again.</li>
              <li>Enter a different user name into the text box and login.</li>
              <li>Notice that the topic you created is listed on the left, but with a gray star next to it - this indicates that you are <i>not</i> subscribed to the room</li>
              <li>In the first browser, send another message - observe that it is received immediately in the first browser window, but not the second.</li>
              <li>In the second browser, type a message in the text box and hit enter - observe that it is received by the first browser window.</li>
              <li>In the second browser, click the gray star next to the topic name to subscribe. <b>NOTE: this sample updates the list of topics and subscriptions in the background roughly once ever 30 seconds.</b></li>
              <li>One the star turns yellow, the subscription has been created - type another message in the text box and press enter</li>
              <li>Notice that the message is delivered to both the first and second browser windows</li>
              <li>Continue typing in the first and second windows as desired - messages are sent to both. Add additional browser windows (on multiple computers, if desired).</li>
              <li>Close one of the browser windows, but continue to send messages in the other</li>
              <li>Re-open the closed window and log in with the same username. Click the name of the topic that messages were sent to while you were offline and notice how they are delivered.</li>
            </ol>
          </p>
      </content>
    </DIV>
    <!--[if gte IE 5]><tool:tip avoidmouse="false" element="languageFilterToolTip"></tool:tip><![endif]-->
  </DIV>
    <hr />
    Did you find this information useful?
    <a href="http://go.microsoft.com/fwlink/?LinkID=155664">
      Please send your suggestions and comments about the documentation.
    </a>
  </DIV>
</BODY></HTML>
